﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
using System.Windows.Forms;

namespace UniversalQueryDemo
{
   public class Person
    {
        private int _Id;

        public int Id
        {
            get
            {
                return _Id;
            }
            set
            {
                _Id = value;
            }
        }

        private string _Name;

        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        private string _Company;

        public string Company
        {
            get
            {
                return _Company;
            }
            set
            {
                _Company = value;
            }
        }
        private string _Occupation;

        public string Occupation
        {
            get
            {
                return _Occupation;
            }
            set
            {
                _Occupation = value;
            }
        }
        private decimal _Salary;

        public decimal Salary
        {
            get
            {
                return _Salary;
            }
            set
            {
                _Salary = value;
            }
        }
        private string _Height;

        public string Height
        {
            get
            {
                return _Height;
            }
            set
            {
                _Height = value;
            }
        }
        public static List<Person> GetPersonList(string strWhere)
        {
            List<Person> pl = new List<Person>();
            try
            {
                SQLiteConnection conn = new SQLiteConnection(string.Format("Data Source={0}/universalquery.db;New=False;Version=3", Application.StartupPath));
                conn.Open();
                SQLiteCommand cmd = new SQLiteCommand(string.Format("select * from contact {0}", strWhere), conn);
                SQLiteDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    Person p = new Person();
                    p.Id = Convert.ToInt32(dr["id"]);
                    p.Company = dr["Company"].ToString();
                    p.Height = dr["Height"].ToString();
                    p.Name = dr["Name"].ToString();
                    p.Occupation = dr["Occupation"].ToString();
                    p.Salary = Convert.ToDecimal(dr["Salary"]);
                    pl.Add(p);
                }
                dr.Close();
                conn.Clone();
            }
            catch (SQLiteException e)
            {
                MessageBox.Show(e.ToString());
            }
            return pl;
        }
    }
}
